package com.ruoyi.web.controller.category;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.category.domain.SysPart;
import com.ruoyi.category.service.ISysPartService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 配件Controller
 * 
 * @author YJF
 */
@RestController
@RequestMapping("/category/part")
public class SysPartController extends BaseController
{
    @Autowired
    private ISysPartService sysPartService;

    /**
     * 查询配件列表
     */
    @PreAuthorize("@ss.hasPermi('category:part:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysPart sysPart)
    {
        startPage();
        List<SysPart> list = sysPartService.selectSysPartList(sysPart);
        return getDataTable(list);
    }

    /**
     * 获取配件详细信息
     */
    @PreAuthorize("@ss.hasPermi('category:part:query')")
    @GetMapping(value = "/{partId}")
    public AjaxResult getInfo(@PathVariable("partId") Long partId)
    {
        return AjaxResult.success(sysPartService.selectSysPartByPartId(partId));
    }

    /**
     * 新增配件
     */
    @PreAuthorize("@ss.hasPermi('category:part:add')")
    @Log(title = "配件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPart sysPart)
    {
        return toAjax(sysPartService.insertSysPart(sysPart));
    }

    /**
     * 修改配件
     */
    @PreAuthorize("@ss.hasPermi('category:part:edit')")
    @Log(title = "配件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPart sysPart)
    {
        return toAjax(sysPartService.updateSysPart(sysPart));
    }

    /**
     * 删除配件
     */
    @PreAuthorize("@ss.hasPermi('category:part:remove')")
    @Log(title = "配件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{partIds}")
    public AjaxResult remove(@PathVariable Long[] partIds)
    {
        return toAjax(sysPartService.deleteSysPartByPartIds(partIds));
    }
}
